<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/26
 * Time: 11:36
 */

namespace app\api\controller;


use app\api\service\Goods;
use app\common\Code;
use app\common\Session;
use think\Config;

class V0
{
    const CAPTCHA_ID = "CAPTCHA_ID";

    /**
     * 主页数据
     * 参数
     * community_id  最好保存到stroge 社区id
     */
    public function index()
    {
        $param = input();
        $cond = [];
        if (isset($param["community_id"])) {
            $cond["shop_community_seller_relation.community_id"] = $param["community_id"];
        } else {
            response_json(Code::COMMUNITY_NOT_FOUND, []);
        }
        $goods = Goods::list_($cond);
        response_json(Code::NONE, $goods);
    }

    /**
     * 发送手机验证码
     * 参数
     * phone
     * pic_captcha
     */
    public function phone_send($phone = 0)
    {
        if (valid_pic_capture(self::CAPTCHA_ID) == false) {
            response_json(Code::PIC_CAPTURE_ERROR);
        }
        # 验证发送验证码时间
        if (empty($phone)) {
            response_json(Code::PARAM_ERROR);
        }
        $code = telephone_send_code($phone);
        response_json(Code::NONE);
    }

    /**
     *生成图片验证码
     * config::get()是系统函数，更新composer.phar，然后执行
     * @return \think\response\Json
     */
    public function pic_captcha()
    {
        return captcha(self::CAPTCHA_ID, Config::get('captcha'));
    }

}